package CircleS;

import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
public class Solution {
	public static void main(String[] args)  throws Exception{
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedReader br = new BufferedReader(new FileReader("src/CircleS/data.txt"));
		String line = br.readLine();
		int T = Integer.parseInt(line);
		for(int i=0;i<=T-1;i++){
			line = br.readLine();
			String str[]=line.split(" ");
			int N=Integer.parseInt(str[0]);
			int M=Integer.parseInt(str[1]);
			line = br.readLine();
			str=line.split(" ");
			int a[]=new int[N];
			int b[][]=new int[N][N];
			for(int j=0;j<=N-1;j++){
				a[j]=Integer.parseInt(str[j]);
				for (int k=0;k<N;k++){
					if(j==k)b[j][k]=1;
					else b[j][k]=0;
				}

			}
			for(int j=0;j<M/N;j++){
				for (int k=0;k<N;k++){
					b[0][k]=(b[0][k]+(b[N-1][k]+b[1][k])%1000000007)%1000000007;
				}
				for(int l=1;l<=N-2;l++){
					for (int k=0;k<N;k++){
						b[l][k]=(b[l][k]+(b[l-1][k]+b[l+1][k])%1000000007)%1000000007;
					}
				}
				for (int k=0;k<N;k++){
					b[N-1][k]=(b[N-1][k]+(b[N-2][k]+b[0][k])%1000000007)%1000000007;
				}
			}

			for(int j=0;j<M%N;j++){
				for (int k=0;k<N;k++){
					b[j%N][k]=(b[j%N][k]+(b[(j+N-1)%N][k]+b[(j+1)%N][k])%1000000007)%1000000007;
				}
			}
			for(int j=0;j<N;j++){
				String s="";
				for(int k=(N-j)%N;;k=(k+1)%N){
					long x=0;
					for(int l=0;l<N;l++){
						x=(int)(x+((long)b[k][l]*a[(l+j)%N])%1000000007)%1000000007;
					}
					s+=x+" ";
					if(k==(N-j-1)%N)break;
				}
				System.out.println(s);
			}
			if(i<T-1)System.out.println("");
		}
		br.close();
	}
}
